﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Diagnostics;
using Contract;

namespace LikeTryCore
{
   
    public class LikeTryOper
    {
        public List<LikeAccount> accountObj { get; set; }

        public LikeTryOper( List<LikeAccount> account)
        {
            accountObj = account;
        }

        public void KeepOnline()
        {
            while (true)
            {
                var start = DateTime.Now.Ticks;
                var deadline = DateTime.Now.AddMinutes(2).Ticks;
                try
                {
                    foreach (var item in accountObj)
                    {
                        LikeTryCore.LikeTry obj = new LikeTryCore.LikeTry(item.Cookies);
                        obj.KeepOnline();
                        if (obj.UserName == "")
                        {
                            EventLog.WriteEntry("Application",item.Name + "Cookies invalid", EventLogEntryType.Error);
                        }
                    }

                    var end = DateTime.Now.Ticks;
                    if (deadline > end)
                    {
                        Thread.Sleep(new TimeSpan(deadline - end));
                    }
                }
                catch
                { }
            }
        }
    }
}
